<template>
<div>
  <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 20px">
    <el-breadcrumb-item :to="{ path: '/' }">后台管理</el-breadcrumb-item>
    <el-breadcrumb-item>新增spu</el-breadcrumb-item>
    <el-breadcrumb-item>第一步选择类别</el-breadcrumb-item>
  </el-breadcrumb>
  <el-divider></el-divider>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="商品类别" prop="categoryId">
      <el-input v-model="ruleForm.categoryId" placeholder="请输入商品类别ID"></el-input>
    </el-form-item>
      <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">下一步</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        categoryId:""
      },
      rules: {
        categoryId: [
          {required: true, message: '请输入商品类别ID', trigger: 'blur'},
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {  let ruleFormString = JSON.stringify(this.ruleForm);
          localStorage.setItem('ruleForm', ruleFormString);

          this.$router.push('spu-add-new2')
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

  },
  mounted() {
    let item = localStorage.getItem('ruleForm');
    if(item){
      let loc=JSON.parse(item)
      this.ruleForm.categoryId=loc.categoryId;
    }
  }
}
</script>